#ifndef __TOYOTA_H__
#define __TOYOTA_H__

#include "includes.h"
#include "vehicle.h"

#define TOYOTA_SUPPORT_RAW_MAX          0x20
#define TOYOTA_SUPPORT_ITEM_MAX         0x30
#define RAW_BUF_MAX_SIZE                1280

#define LF_WINDOW_MODULE                0x90
#define RF_WINDOW_MODULE                0x91
#define LR_WINDOW_MODULE                0x93
#define RR_WINDOW_MODULE                0x92

#define DOOR_MODULE                     0x40

typedef struct {
    uint8_t pid;
    uint8_t len;
    uint8_t raw_data[TOYOTA_SUPPORT_RAW_MAX];
} ToyotaSupportPid;

typedef struct {
    uint8_t id;
    uint8_t pid;
    uint8_t offset;
    uint8_t size;
    uint8_t support;
} ToyotaEngData;

typedef struct {
    uint8_t id;
    uint8_t module_id;
    uint8_t pid;
    uint8_t offset;
    uint8_t size;
    uint8_t support;
} ToyotaBcmData;

typedef struct {
    uint8_t module_id;
    ToyotaSupportPid supportPid[TOYOTA_SUPPORT_ITEM_MAX];
} BcmModuleSupport;

void toyota_init(Vehicle *vehicle);

uint8_t toyota_check_engine_on(void);
void toyota_get_rpm(uint16_t *rpm);
void toyota_process_eng_data(EngineDataMap *dataMap);
void toyota_process_bcm_window_data(BcmDataMap *dataMap);

void toyota_eng_support(void);
void toyota_bcm_support(BcmModuleSupport *moduleSupport);
uint8_t toyota_clear_fault_code(uint8_t type);
void toyota_get_fault_code(uint8_t type, FaultCodeItem *item);

void toyota_bcm_keepalive(uint8_t module);

uint8_t toyota_check_eng_pid_supported(uint8_t pid);

#endif
